/*
 * TCSS 422 Process Control Simulator
 * Group Money: Al McKenzie, Michael Pitts, Taylor Zielske
 */

/**
 * An Interrupt given to the CPU during run time.
 * 
 * @author Michael Pitts
 * @version Dec 8, 2011
 */
public final class Interrupt {
	
	/**
	 * Indicates a timer Interrupt.
	 */
	public static final int TIMER = 0;
	
	/**
	 * Indicates an Input/Output Interrupt.
	 */
	public static final int IO = 1;

	/**
	 * The type of this interrupt.
	 */
	private final int my_type;

	/**
	 * The IODevice that triggered this interrupt.
	 */
	private final IODevice my_device;
	
	/**
	 * Creates a new Timer Interrupt.
	 */
	public Interrupt() {
		this(TIMER, null);
		Main.out().println("Timer Interrupt");
	}
	
	/**
	 * Creates a new IODevice Interrupt.
	 * @param the_device is the IODevice that triggered the interupt.
	 */
	public Interrupt(final IODevice the_device) {
		this(IO, the_device);
		Main.out().println(the_device.toString() + " Interrupt");
	}
	
	/**
	 * Creates a new IODevice Interrupt, however the device is null and only
	 * the given text is output.
	 * @param the_text is the text to display in the interrupt.
	 */
	public Interrupt(final String the_text) {
		this(IO, null);
		Main.out().println("Keyboard Interrupt " + the_text);
	}
	
	/**
	 * Creates a new Interrupt.
	 * @param the_type is the type.
	 * @param the_device is the device triggering the interrupt, may be null.
	 */
	private Interrupt(final int the_type, final IODevice the_device) {
		my_type = the_type;
		my_device = the_device;
	}
	
	/**
	 * Gets the type of interrupt.
	 * @return the type of interrupt.
	 */
	public int getType() {
		return my_type;
	}
	
	/**
	 * Gets the IODevice which triggered the Interrupt.
	 * @return the device triggering the Interrupt.
	 */
	public IODevice getDevice() {
		return my_device;
	}

}
